package bsts.view.complaint;
import java.util.*;
import javax.swing.*;
import bsts.controller.ComplaintController;
import bsts.view.util.GridColumn;
import bsts.view.util.GridControl;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
/*
 * Author 		: Lee Zhong De Rollei
 * Student ID	: A0079953L
 */


public class ViewComplaintsFrm extends JFrame implements MouseListener{
	
	/*Local attributes=================================================================================================*/
	//required as it references serializable objects for binary saving
	private static final long serialVersionUID = 1L;
	//Reusing common grid control
	private	GridControl gridFrm;

	/*Constructors=======================================================================================================*/
	public ViewComplaintsFrm()
	{
		//Define GridColumn to bind to common control
		ArrayList<GridColumn> gridCol = new ArrayList<GridColumn>();
		gridCol.add(new GridColumn("Complain ID","getComplaintId",50));
		gridCol.add(new GridColumn("User ID","getUserId",50));
		gridCol.add(new GridColumn("Date/Time","getTimestampStr",90));
		gridCol.add(new GridColumn("Customer NRIC","getCustomerNric",50));
		gridCol.add(new GridColumn("Complaint","getComplaint",160));
		gridCol.add(new GridColumn("Status","getComplaintStatus",50));
		
		//Get the source data to bind to common control
		//ArrayList<?> objList = new ComplaintController().();		
		gridFrm= new GridControl(600,500,new ComplaintController(),"getComplaints" ,gridCol,true, this);
				
		//add common grid control to customer frame
		add(gridFrm);
		setSize(600,500);
		
	}
	

	/*Public methods Events handler=====================================================================================================*/
	
	public void refreshGrid(){
		this.gridFrm.refreshGrid();
	}
	
	public void mouseClicked(java.awt.event.MouseEvent e){	
		//handle double click event
		if (e.getClickCount() == 2) {
			 //Points
			int row=gridFrm.getGrid().rowAtPoint(e.getPoint());		 
		 	long complaint_id = Long.parseLong(gridFrm.getGrid().getValueAt(row,0).toString());
			ViewEditComplaintFrm frm = new ViewEditComplaintFrm(this,complaint_id,620,470);
			frm.setVisible(true);		
		}
		 
	 }
	
	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	

}
